package j03sisuo;

public class J1 {
    static Thread t1;
    static Thread t2;
    static Object lock1 = new Object();
    static Object lock2 = new Object();
    public static void main(String[] args) {
        t1 = new Thread(){
            @Override
            public void run() {
                System.out.println("enter t1");
                synchronized (lock1){
                    System.out.println("t1 lock1");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                    synchronized (lock2){
                        System.out.println("t1 enter lock2");
                    }
                }

                System.out.println("t1 end");
            }
        };
        t2 = new Thread(){
            @Override
            public void run() {
                System.out.println("enter t2");
                synchronized (lock2){
                    System.out.println("t2 lock2");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                    synchronized (lock1){
                        System.out.println("t2 enter lock1");
                    }
                }
                System.out.println("t2 end");
            }
        };
        t1.start();
        t2.start();
    }
}
